/**
 * TokUI 体验中心样式
 * 布局：顶栏 + 左侧导航 + 右侧预览 + 底栏
 */

/* === 重置 & 变量 === */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #1677ff;
  --primary-hover: #0958d9;
  --primary-light: #e6f4ff;
  --primary-border: #91caff;
  --bg: #f8fafc;
  --bg-white: #ffffff;
  --bg-nav: #fafbfd;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,0.06);
  --radius: 8px;
  --radius-sm: 6px;
  --header-h: 52px;
  --footer-h: 36px;
  --nav-w: 260px;
  --transition: 0.15s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-white);
}

/* === Header === */
.app-header {
  height: var(--header-h);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-white);
  flex-shrink: 0;
  z-index: 10;
}

.app-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-logo {
  font-family: 'Courier New', Courier, monospace;
  background: var(--primary);
  color: #fff;
  padding: 2px 10px;
  border-radius: 4px;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 2px;
}

.app-tagline {
  font-size: 0.72rem;
  color: var(--primary);
  font-weight: 500;
}

.app-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header-center {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: 0 12px;
}

.app-construction-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
  font-weight: 500;
}

body.dark .app-construction-badge {
  color: #fbbf24;
  background: #451a03;
  border-color: #78350f;
}

.app-header-btn svg {
  flex-shrink: 0;
}

/* Search */
.app-search {
  position: relative;
  display: flex;
  align-items: center;
  width: 220px;
  height: 32px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 10px;
  transition: all 0.2s;
}

.app-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(22, 119, 255, 0.1);
  background: var(--bg-white);
}

.app-search-icon {
  flex-shrink: 0;
  color: var(--text-3);
  transition: color 0.2s;
}

.app-search:focus-within .app-search-icon {
  color: var(--primary);
}

.app-search-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 0.8rem;
  color: var(--text);
  padding: 0 6px;
  height: 100%;
  width: 100%;
}

.app-search-input::placeholder {
  color: var(--text-3);
}

.app-search-kbd {
  font-family: inherit;
  font-size: 0.65rem;
  color: var(--text-3);
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
  line-height: 1.4;
}

.app-search:focus-within .app-search-kbd {
  display: none;
}

.app-search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  max-height: 360px;
  overflow-y: auto;
  display: none;
  z-index: 100;
  padding: 4px;
}

.app-search-dropdown.active {
  display: block;
}

.app-search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.app-search-item:hover,
.app-search-item.active {
  background: var(--primary-light);
}

.app-search-item-icon {
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(22, 119, 255, 0.08);
  border-radius: 6px;
  font-size: 0.75rem;
  color: var(--primary);
  flex-shrink: 0;
  font-style: normal;
}

.app-search-item-body {
  flex: 1;
  min-width: 0;
}

.app-search-item-name {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-search-item-name mark {
  background: none;
  color: var(--primary);
  font-weight: 700;
}

.app-search-item-desc {
  font-size: 0.68rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-search-empty {
  padding: 20px 10px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-3);
}

.app-header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 5px 10px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;   /* 官网等 <a> 按钮去下划线 */
  transition: background var(--transition);
}

.app-header-btn:hover {
  background: var(--primary-light);
}

.app-header-btn--pill {
  background: var(--primary-light);
  padding: 4px 12px;
  border-radius: 6px;
}

.app-header-btn--pill:hover {
  background: var(--primary-border);
}

.app-header-repos {
  display: flex;
  align-items: center;
  gap: 4px;
}

.app-header-repo-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-header-repo-icon svg {
  width: 100%;
  height: 100%;
}

.app-header-btn--icon {
  padding: 5px;
  color: var(--text-2);
}

.app-header-btn--icon:hover {
  color: var(--primary);
  background: var(--primary-light);
}

body.dark .app-header-btn--icon {
  color: #94a3b8;
}

body.dark .app-header-btn--icon:hover {
  color: #60a5fa;
  background: rgba(96, 165, 250, 0.12);
}

/* Mode Toggle */
.app-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-white);
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--text-3);
  flex-shrink: 0;
}

.app-footer-left,
.app-footer-center,
.app-footer-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-footer-left { flex: 0 0 auto; }
.app-footer-center { flex: 1 1 auto; justify-content: center; }
.app-footer-right { flex: 0 0 auto; }

.app-footer-logo {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--primary);
  letter-spacing: -0.02em;
}

.app-footer-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
  flex-shrink: 0;
}

.app-footer-ver {
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}

.app-footer-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
  transition: color var(--transition);
}

.app-footer-btn:hover {
  color: var(--primary);
}

.app-footer-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-2);
  text-decoration: none;
  font-weight: 500;
  transition: color var(--transition);
}

.app-footer-link:hover {
  color: var(--primary);
}

.app-footer-link-icon {
  flex-shrink: 0;
}

.app-footer-copy {
  font-size: 0.68rem;
  color: var(--text-3);
}

/* === Stream Mode Toggle === */

.app-mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-icon {
  flex-shrink: 0;
  color: var(--text-3);
}

.mode-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-2);
  user-select: none;
}

.mode-switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
}

.mode-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.mode-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 18px;
  transition: background var(--transition);
}

.mode-slider::before {
  content: '';
  position: absolute;
  height: 12px;
  width: 12px;
  left: 3px;
  bottom: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform var(--transition);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.mode-switch input:checked + .mode-slider {
  background: var(--primary);
}

.mode-switch input:checked + .mode-slider::before {
  transform: translateX(14px);
}

.mode-switch input:focus-visible + .mode-slider {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.app-menu-toggle {
  display: flex;
}

/* === Body Layout === */
.app-body {
  flex: 1;
  min-height: 0;
  display: flex;
}

/* === Sidebar Navigation === */
.app-nav {
  width: var(--nav-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-nav);
  overflow-y: auto;
  overflow-x: hidden;
  /* margin-left 折叠：nav 保持 260 宽（内容不挤压），整块左滑出 + 主区扩展，丝滑无变形 */
  transition: transform 0.25s ease, margin-left 0.25s ease, background 0.2s, border-color 0.2s;
}

/* 桌面折叠（主流 sidebar toggle）：scope 到 min-width:769，避免污染移动 off-canvas。
   用 margin-left 负值把整块 nav 滑出视口左缘（内容维持原宽不挤压），主区自动扩展填满 */
@media (min-width: 769px) {
  .app-nav.collapsed {
    margin-left: calc(-1 * var(--nav-w));
    border-right-color: transparent;
  }
}

.app-nav-inner {
  padding: 12px 0 20px;
}

/* Category */
.nav-category {
  margin-bottom: 2px;
}

.nav-category-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: 0.3px;
  transition: all 0.2s;
  position: relative;
  border-radius: 6px;
  margin: 0 8px;
}

.nav-category-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 16px;
  right: 16px;
  height: 1px;
  background: var(--border);
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-category-header:hover::after {
  opacity: 0.4;
}

.nav-category-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  opacity: 0.55;
  flex-shrink: 0;
  transition: opacity 0.2s;
}

.nav-category-icon svg {
  width: 18px;
  height: 18px;
}

.nav-category-label {
  flex: 1;
}

.nav-category-header:hover {
  color: var(--primary);
  background: rgba(22, 119, 255, 0.04);
}

.nav-category-header:hover .nav-category-icon {
  opacity: 0.85;
}

.nav-category-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  transition: transform 0.25s ease, opacity 0.2s;
  opacity: 0.35;
  margin-left: auto;
  flex-shrink: 0;
}

.nav-category-arrow svg {
  width: 16px;
  height: 16px;
}

.nav-category-header:hover .nav-category-arrow {
  opacity: 0.65;
}

.nav-category.collapsed .nav-category-arrow {
  transform: rotate(-90deg);
}

.nav-category-items {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.25s ease;
}

.nav-category-items.expanded {
  opacity: 1;
}

/* Nav Item */
.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px 7px 16px;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.nav-item:hover {
  background: var(--primary-light);
}

.nav-item.active {
  background: var(--primary);
}

.nav-item.active .nav-item-name {
  color: #fff;
  font-weight: 600;
}

.nav-item.active .nav-item-desc {
  color: rgba(255,255,255,0.7);
}

.nav-item-icon {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 0.85rem;
  flex-shrink: 0;
  font-style: normal;
  background: var(--bg-white);
  border-radius: 5px;
  border: 1px solid var(--border);
  transition: all var(--transition);
}

.nav-item.active .nav-item-icon {
  color: #fff;
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.3);
}

.nav-item-text {
  flex: 1;
  min-width: 0;
}

.nav-item-name {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.3;
}

.nav-item-desc {
  font-size: 0.68rem;
  color: var(--text-3);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-item-play {
  opacity: 0;
  color: var(--text-3);
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.nav-item.active .nav-item-play {
  color: rgba(255,255,255,0.7);
}

.nav-item:hover .nav-item-play {
  opacity: 1;
}

/* === Main Preview Area === */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Welcome State */
.app-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 20px;
  position: relative;
  overflow: hidden;
}

/* Grid background */
.app-welcome::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(99,102,241,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99,102,241,0.06) 1px, transparent 1px);
  background-size: 28px 28px;
  pointer-events: none;
}

/* Glow */
.app-welcome::after {
  content: '';
  position: absolute;
  width: 400px;
  height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,0.06) 0%, transparent 70%);
  top: 20%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.app-welcome-top {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.app-welcome-logo {
  font-family: 'Courier New', Courier, monospace;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -1px;
}

.app-welcome-subtitle {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.82rem;
  color: var(--text-2);
  opacity: 0;
  animation: welcomeFadeIn 0.4s ease 0.9s forwards;
}

/* Token Flow */
.app-welcome-token-flow {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  opacity: 0;
  animation: welcomeFadeIn 0.4s ease 0.7s forwards;
}

.token-flow-word {
  color: var(--text-3);
  font-weight: 500;
  opacity: 0;
  animation: tokenWordIn 0.3s ease forwards;
}

.token-flow-accent {
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 700;
  font-size: 0.88rem;
}

.token-flow-arrow {
  color: rgba(99,102,241,0.35);
  font-size: 0.7rem;
  opacity: 0;
  animation: tokenArrowIn 0.25s ease forwards;
}

.token-flow-word[data-delay="0"] { animation-delay: 0.7s; }
.token-flow-arrow[data-delay="1"] { animation-delay: 0.77s; }
.token-flow-word[data-delay="2"] { animation-delay: 0.82s; }
.token-flow-arrow[data-delay="3"] { animation-delay: 0.89s; }
.token-flow-word[data-delay="4"] { animation-delay: 0.94s; }
.token-flow-arrow[data-delay="5"] { animation-delay: 1.01s; }
.token-flow-word[data-delay="6"] { animation-delay: 1.06s; }

@keyframes tokenWordIn {
  from { opacity: 0; transform: translateY(4px); filter: blur(3px); }
  to   { opacity: 1; transform: translateY(0);    filter: blur(0); }
}

@keyframes tokenArrowIn {
  from { opacity: 0; transform: translateX(-3px); }
  to   { opacity: 1; transform: translateX(0); }
}

.app-welcome-features {
  display: flex;
  gap: 10px;
  flex-wrap: nowrap;
  justify-content: center;
  margin-top: 4px;
}

.app-welcome-feat {
  padding: 4px 12px;
  background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.18);
  border-radius: 6px;
  font-size: 0.76rem;
  color: var(--primary);
  font-family: 'Courier New', Courier, monospace;
  opacity: 0;
  transform: translateY(8px);
  animation: welcomeFadeUp 0.4s ease forwards;
}

.app-welcome-feat:nth-child(1) { animation-delay: 0.9s; }
.app-welcome-feat:nth-child(2) { animation-delay: 1.05s; }
.app-welcome-feat:nth-child(3) { animation-delay: 1.2s; }
.app-welcome-feat:nth-child(4) { animation-delay: 1.35s; }

.app-welcome-credit {
  margin-top: 10px;
  opacity: 0;
  transform: translateY(8px);
  animation: welcomeFadeUp 0.4s ease 1.5s forwards;
}

.app-welcome-credit-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: opacity 0.15s;
}

.app-welcome-credit-link:hover {
  opacity: 0.8;
}

.app-welcome-credit-icon {
  font-size: 0.85rem;
  -webkit-text-fill-color: #ef4444;
}

.app-welcome-demo {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  width: 100%;
  max-width: 860px;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 0 0 1px rgba(99,102,241,0.1);
  opacity: 0;
  animation: welcomeFadeIn 0.5s ease 1.5s forwards;
}

.app-welcome-dsl {
  background: #1e293b;
  padding: 14px 16px;
  position: relative;
  height: 320px;
  overflow-y: auto;
}

.app-welcome-dsl-header {
  color: #475569;
  font-size: 0.65rem;
  font-family: 'Courier New', Courier, monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.app-welcome-dsl-code {
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #e2e8f0;
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0;
  padding: 0;
}

.app-welcome-cursor {
  display: inline-block;
  width: 7px;
  height: 14px;
  background: var(--primary);
  animation: cursorBlink 1s step-end infinite;
  vertical-align: middle;
  position: absolute;
}

.app-welcome-preview {
  background: var(--bg-white);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  height: 320px;
}

.app-welcome-preview-header {
  color: var(--text-3);
  font-size: 0.65rem;
  font-family: 'Courier New', Courier, monospace;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.app-welcome-preview-body {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
}

.app-welcome-footer {
  position: relative;
  z-index: 1;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.72rem;
  color: var(--text-3);
  opacity: 0;
  animation: welcomeFadeIn 0.4s ease 1.8s forwards;
}

.app-welcome-flow {
  display: inline-block;
}

/* Welcome animations */
@keyframes welcomeFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes welcomeFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes cursorBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* === Chat Messages === */
.msg {
  max-width: 95%;
  animation: msgFadeIn 0.3s ease;
}

.msg--user {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  padding: 10px 18px;
  border-radius: 18px 18px 4px 18px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.msg--ai {
  align-self: flex-start;
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  width: 100%;
  max-width: 100%;
}

/* AI toolbar */
.msg-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.msg-stats {
  font-size: 0.7rem;
  color: var(--text-3);
  white-space: nowrap;
  margin-right: auto;
}

.msg-toolbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-nav);
  color: var(--text-2);
  font-size: 0.73rem;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1.6;
}

.msg-toolbar-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

/* Thinking indicator */
.msg-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  color: var(--text-3);
  font-size: 0.82rem;
}

.msg-thinking-dots {
  display: flex;
  gap: 4px;
}

.msg-thinking-dots span {
  width: 6px;
  height: 6px;
  background: var(--text-3);
  border-radius: 50%;
  animation: thinkPulse 1.4s ease-in-out infinite;
}

.msg-thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.msg-thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinkPulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.1); }
}

/* Source code area */
.msg-source {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-family: 'Fira Code', 'Consolas', 'Monaco', monospace;
  font-size: 0.78rem;
  line-height: 1.6;
  overflow-x: auto;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-all;
}

/* TokUI DSL 语法高亮配色（与文档站 Playground 同源）。
   默认浅色板（适配 .tokui-card-source 的浅色 --tokui-stripe 底），
   body.dark 切深色板，.msg-source 因恒为深底强制深色板。 */
.tok-bracket { color: #94a3b8; }
.tok-tag      { color: #7c3aed; font-weight: 600; }
.tok-attr     { color: #0e7490; }
.tok-punct    { color: #94a3b8; }
.tok-val      { color: #b45309; }
.tok-variant  { color: #be123c; }
.tok-string   { color: #15803d; }
.tok-bool     { color: #1d4ed8; }
.tok-text     { color: #475569; }
body.dark .tok-bracket { color: #64748b; }
body.dark .tok-tag      { color: #c084fc; }
body.dark .tok-attr     { color: #22d3ee; }
body.dark .tok-punct    { color: #64748b; }
body.dark .tok-val      { color: #fbbf24; }
body.dark .tok-variant  { color: #fb7185; }
body.dark .tok-string   { color: #4ade80; }
body.dark .tok-bool     { color: #60a5fa; }
body.dark .tok-text     { color: #cbd5e1; }
/* .msg-source 恒深底 → 永远用深色板 */
.msg-source .tok-bracket { color: #64748b; }
.msg-source .tok-tag      { color: #c084fc; font-weight: 600; }
.msg-source .tok-attr     { color: #22d3ee; }
.msg-source .tok-punct    { color: #64748b; }
.msg-source .tok-val      { color: #fbbf24; }
.msg-source .tok-variant  { color: #fb7185; }
.msg-source .tok-string   { color: #4ade80; }
.msg-source .tok-bool     { color: #60a5fa; }
.msg-source .tok-text     { color: #cbd5e1; }

/* System message */
.msg--system {
  align-self: center;
  background: #fef3c7;
  color: #92400e;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.82rem;
  max-width: 80%;
  text-align: center;
}

.msg--system pre {
  text-align: left;
  background: rgba(0,0,0,0.05);
  padding: 8px;
  border-radius: 4px;
  margin-top: 6px;
  font-size: 0.76rem;
  overflow-x: auto;
}

/* Loading */
.msg--loading {
  display: flex;
  gap: 6px;
  padding: 12px 18px;
  align-self: flex-start;
}

.loading-dot {
  width: 8px;
  height: 8px;
  background: var(--text-3);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Footer === */
.app-footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-white);
  font-size: 0.72rem;
  color: var(--text-3);
  flex-shrink: 0;
}

.app-footer-link {
  color: var(--primary);
  text-decoration: none;
}

.app-footer-link:hover {
  text-decoration: underline;
}

/* === DSL Reference Dialog === */
.app-dsl-dialog {
  border: none;
  border-radius: 12px;
  max-width: 880px;
  width: 92%;
  padding: 0;
  box-shadow: 0 25px 80px rgba(0,0,0,0.2);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  overflow: hidden;
}

.app-dsl-dialog::backdrop {
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
}

.app-dsl-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px 28px 0;
}

.app-dsl-header h3 {
  font-size: 1.1rem;
  color: var(--text);
  font-weight: 700;
}

.app-dsl-header-sub {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 4px;
}

.app-dsl-close {
  background: var(--bg-nav);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--text-3);
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  transition: all var(--transition);
}

.app-dsl-close:hover {
  background: #ef4444;
  border-color: #ef4444;
  color: #fff;
}

.app-dsl-body {
  padding: 20px 28px 28px;
  max-height: 68vh;
  overflow-y: auto;
}

/* === Contact QR Dialog === */
.app-qr-dialog {
  border: none;
  border-radius: 12px;
  max-width: 320px;
  width: 92%;
  padding: 0;
  box-shadow: 0 25px 80px rgba(0,0,0,0.2);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  overflow: hidden;
  text-align: center;
}

.app-qr-dialog::backdrop {
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(4px);
}

.app-qr-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 20px 0;
}

.app-qr-header h3 {
  font-size: 1.05rem;
  color: var(--text);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-qr-title-icon {
  color: var(--primary);
  flex-shrink: 0;
}

.app-qr-header-sub {
  font-size: 0.75rem;
  color: var(--text-3);
  margin-top: 4px;
}

.app-qr-body {
  padding: 16px 24px 24px;
}

.app-qr-body img {
  width: 180px;
  height: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  object-fit: contain;
}

/* 社群弹层加大变体：竖版 qrcode 按视口高度等比缩放（保持宽高比，不再被方形 letterbox 压小）*/
.app-qr-dialog--lg { max-width: 420px; }
.app-qr-dialog--lg .app-qr-body { text-align: center; }
.app-qr-dialog--lg .app-qr-body img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 70vh;
  border-radius: 10px;
}

.app-qr-body p {
  margin-top: 12px;
  font-size: 0.8rem;
  color: var(--text-2);
}

body.dark .app-qr-dialog { background: #1e293b; }
body.dark .app-qr-header h3 { color: #f1f5f9; }
body.dark .app-qr-header-sub { color: #94a3b8; }
body.dark .app-qr-body p { color: #cbd5e1; }

.app-qr-footer {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

.app-qr-footer-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  background: linear-gradient(135deg, var(--primary), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  transition: opacity 0.15s;
}

.app-qr-footer-link:hover {
  opacity: 0.8;
}

.app-qr-footer-icon {
  font-size: 0.85rem;
  -webkit-text-fill-color: #ef4444;
}

body.dark .app-qr-footer {
  border-color: #334155;
}

/* Section card */
.dsl-section {
  margin-bottom: 20px;
}

.dsl-section:last-child {
  margin-bottom: 0;
}

.dsl-section-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dsl-section-title::before {
  content: '';
  width: 3px;
  height: 14px;
  background: var(--primary);
  border-radius: 2px;
}

/* Syntax block */
.dsl-syntax-row {
  display: flex;
  gap: 12px;
  margin-bottom: 6px;
}

.dsl-syntax-item {
  flex: 1;
  background: var(--bg-nav);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.dsl-syntax-item code {
  display: block;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.8rem;
  color: var(--primary);
  margin-bottom: 4px;
}

.dsl-syntax-item span {
  font-size: 0.72rem;
  color: var(--text-3);
}

/* Attr grid */
.dsl-attr-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}

.dsl-attr-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--bg-nav);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
}

.dsl-attr-key {
  font-family: 'Fira Code', 'Consolas', monospace;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.76rem;
}

.dsl-attr-val {
  color: var(--text-3);
  font-size: 0.72rem;
}

/* Container tag chips */
.dsl-tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.dsl-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 4px 10px;
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: 14px;
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.74rem;
  color: var(--primary);
}

/* Component list with descriptions */
.dsl-comp-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.dsl-comp-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
}
.dsl-comp-tag {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.74rem;
  padding: 3px 10px;
  border-radius: 4px;
  white-space: nowrap;
  min-width: 110px;
  text-align: center;
}
.dsl-comp-self {
  background: rgba(34, 197, 94, 0.1);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #16a34a;
}
.dsl-comp-container {
  background: rgba(22, 119, 255, 0.1);
  border: 1px solid rgba(22, 119, 255, 0.3);
  color: #1677ff;
}
.dsl-comp-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Code example */
.dsl-example {
  background: #1e1e2e;
  color: #cdd6f4;
  padding: 16px 18px;
  border-radius: var(--radius);
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  overflow-x: auto;
  margin: 0;
  white-space: pre;
}

.dsl-example .dsl-hl-tag {
  color: #89b4fa;
}

.dsl-example .dsl-hl-attr {
  color: #f9e2af;
}

.dsl-example .dsl-hl-val {
  color: #a6e3a1;
}

/* DSL preview render */
.dsl-example-wrap { margin-top: 0; }
.dsl-example-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 0;
  padding: 6px 12px;
  background: #181825;
  border-radius: var(--radius) var(--radius) 0 0;
  font-size: 0.75rem;
}
.dsl-example-label {
  font-family: 'Fira Code', 'Consolas', monospace;
  color: #7f849c;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.dsl-render-btn {
  margin-left: auto;
  padding: 3px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 0.72rem;
  cursor: pointer;
  transition: background 0.15s;
}
.dsl-render-btn:hover {
  background: var(--primary-hover-solid, #0958d9);
}
.dsl-example-wrap .dsl-example {
  border-radius: 0 0 var(--radius) var(--radius);
}
.dsl-preview {
  display: none;
  padding: 16px;
  border: 1px solid #313244;
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--bg);
  max-height: 420px;
  overflow-y: auto;
}
.dsl-preview .tokui-root {
  font-size: 14px;
}

/* === Scrollbar === */
.app-messages::-webkit-scrollbar,
.app-nav::-webkit-scrollbar {
  width: 5px;
}

.app-messages::-webkit-scrollbar-track,
.app-nav::-webkit-scrollbar-track {
  background: transparent;
}

.app-messages::-webkit-scrollbar-thumb,
.app-nav::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

.app-messages::-webkit-scrollbar-thumb:hover,
.app-nav::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

/* Nav scrollbar — lighter & thinner */
.app-nav::-webkit-scrollbar {
  width: 3px;
}
.app-nav::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.06);
}
.app-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.12);
}

/* === Dark Mode === */
body.dark {
  --bg: #0f172a;
  --bg-white: #1e293b;
  --bg-nav: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --primary-light: rgba(22, 119, 255, 0.15);
  --primary-border: #0958d9;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
}

body.dark .app-header {
  border-bottom-color: var(--border);
}

body.dark .app-logo {
  background: #3c9eff;
  color: #121e32;
}

body.dark .app-tagline {
  color: #61a1e8;
}

body.dark .app-header-btn {
  color: #61a1e8;
}

body.dark .app-header-btn:hover {
  background: rgba(57, 131, 220, 0.15);
}

body.dark .app-search {
  background: #1e293b;
  border-color: #334155;
}

body.dark .app-search:focus-within {
  background: #1e293b;
  border-color: #3c9eff;
  box-shadow: 0 0 0 3px rgba(60, 158, 255, 0.12);
}

body.dark .app-search-kbd {
  background: #0f172a;
  border-color: #475569;
  color: #64748b;
}

body.dark .app-search-dropdown {
  background: #1e293b;
  border-color: #334155;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

body.dark .app-search-item:hover,
body.dark .app-search-item.active {
  background: rgba(60, 158, 255, 0.1);
}

body.dark .app-search-item-icon {
  background: rgba(60, 158, 255, 0.12);
  color: #3c9eff;
}

body.dark .app-search-item-name mark {
  color: #3c9eff;
}

body.dark .app-header-btn--pill {
  background: rgba(57, 131, 220, 0.15);
}

body.dark .msg--user {
  background: #0958d9;
}

body.dark .msg--ai {
  background: #1e293b;
  border-color: #334155;
}

body.dark .msg--system {
  background: #422006;
  color: #fbbf24;
}

body.dark .msg-toolbar-btn {
  background: #334155;
  border-color: #475569;
  color: #94a3b8;
}

body.dark .msg-toolbar-btn:hover {
  background: rgba(22, 119, 255, 0.2);
  color: #3c9eff;
  border-color: #0958d9;
}

body.dark .app-dsl-dialog {
  background: #1e293b;
  color: #e2e8f0;
  box-shadow: 0 25px 80px rgba(0,0,0,0.5);
}

body.dark .app-dsl-close {
  background: #334155;
  border-color: #475569;
  color: #94a3b8;
}

body.dark .dsl-attr-item,
body.dark .dsl-syntax-item {
  background: #334155;
  border-color: #475569;
}

body.dark .dsl-tag {
  background: rgba(57, 131, 220, 0.12);
  border-color: #0958d9;
}

body.dark .dsl-comp-self {
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.3);
  color: #4ade80;
}
body.dark .dsl-comp-container {
  background: rgba(57, 131, 220, 0.12);
  border-color: rgba(57, 131, 220, 0.3);
  color: #3c9eff;
}
body.dark .dsl-comp-desc {
  color: #94a3b8;
}
body.dark .dsl-render-btn {
  background: #3c9eff;
}
body.dark .dsl-render-btn:hover {
  background: #0958d9;
}
body.dark .dsl-preview {
  border-color: #475569;
  background: #1e293b;
}
body.dark .dsl-example-bar {
  background: #111827;
}

body.dark .app-welcome-feat {
  background: rgba(57, 131, 220, 0.12);
  border-color: rgba(57, 131, 220, 0.25);
  color: #3c9eff;
}

body.dark .app-welcome::before {
  background-image:
    linear-gradient(rgba(57, 131, 220, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 131, 220, 0.06) 1px, transparent 1px);
}

body.dark .app-welcome::after {
  background: radial-gradient(circle, rgba(57, 131, 220, 0.06) 0%, transparent 70%);
}

body.dark .token-flow-arrow {
  color: rgba(57, 131, 220, 0.35);
}

body.dark .token-flow-accent {
  background: linear-gradient(135deg, #3c9eff, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

body.dark .app-welcome-dsl {
  background: #0f172a;
}

body.dark .app-welcome-preview {
  background: #1e293b;
}

body.dark .app-nav {
  background: #111827;
  border-right-color: #1e293b;
}

body.dark .nav-item:hover {
  background: rgba(57, 131, 220, 0.1);
}

body.dark .nav-item.active {
  background: var(--primary);
}

body.dark .nav-item-icon {
  background: #1e293b;
  border-color: #334155;
}

body.dark .nav-item.active .nav-item-icon {
  background: rgba(255,255,255,0.15);
  border-color: rgba(255,255,255,0.2);
}

body.dark .nav-category-header {
  color: #94a3b8;
}

body.dark .nav-category-header:hover {
  color: #3c9eff;
  background: rgba(60, 158, 255, 0.06);
}

/* === Responsive (Mobile < 768px) === */
@media (max-width: 768px) {
  .app-menu-toggle {
    display: flex;
  }

  .app-nav {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: var(--footer-h);
    z-index: 20;
    transform: translateX(-100%);
    box-shadow: 2px 0 12px rgba(0,0,0,0.1);
  }

  .app-nav.open {
    transform: translateX(0);
  }

  .app-mode-toggle {
    display: flex;
  }

  .app-tagline {
    display: none;
  }

  .app-header-center {
    display: none;
  }

  .app-header-repos {
    display: none;
  }

  /* 移动端 header 精简：隐藏低优先级，pill 按钮仅显图标 */
  #langToggle,
  #styleFamily,
  .app-search-kbd {
    display: none !important;
  }
  /* 官网/社群/联系 pill 仅显图标，省横向空间 */
  #officialSiteText,
  #communityText,
  #contactBtnText {
    display: none;
  }
  /* 搜索框收窄 */
  .app-search { width: 36px; min-width: 0; }
  .app-search:focus-within { width: 120px; }
  .app-search-input { width: 100%; min-width: 0; }

  .app-footer-left,
  .app-footer-right {
    display: none;
  }

  .app-footer-center {
    justify-content: center;
    gap: 10px;
  }

  .app-footer {
    justify-content: center;
  }

  /* Welcome responsive */
  .app-welcome {
    padding: 16px 12px;
    gap: 14px;
  }

  .app-welcome-logo {
    font-size: 1.6rem;
  }

  .app-welcome-subtitle {
    font-size: 0.72rem;
  }

  .app-welcome-token-flow {
    font-size: 0.68rem;
    gap: 4px;
  }

  .token-flow-accent {
    font-size: 0.76rem;
  }

  .app-welcome-features {
    gap: 6px;
  }

  .app-welcome-feat {
    padding: 3px 8px;
    font-size: 0.68rem;
  }

  .app-welcome-dsl-header,
  .app-welcome-preview-header {
    display: none;
  }

  .app-welcome-demo {
    grid-template-columns: 1fr;
    max-width: 100%;
  }

  .app-welcome-dsl {
    height: 230px;
  }

  .app-welcome-preview {
    height: 280px;
    padding: 8px 10px;
  }

  .app-welcome-preview-body {
    padding: 8px;
  }

  .app-welcome-preview-body .tokui-row {
    grid-template-columns: repeat(12, 1fr);
    gap: 6px;
  }

  .app-welcome-preview-body .tokui-col {
    grid-column: span 4 !important;
  }

  .app-welcome-footer {
    font-size: 0.65rem;
  }

  .app-search {
    width: 32px;
    padding: 0;
    justify-content: center;
    overflow: hidden;
  }

  .app-search-input,
  .app-search-kbd {
    display: none;
  }

  .app-search.expanded {
    position: fixed;
    top: 6px;
    left: 10px;
    right: 10px;
    width: auto;
    padding: 0 10px;
    z-index: 200;
    justify-content: flex-start;
    overflow: visible;
  }

  .app-search.expanded .app-search-input {
    display: block;
  }

  .app-search.expanded .app-search-dropdown {
    left: -10px;
    right: -10px;
    max-height: 50vh;
    border-radius: 0 0 10px 10px;
  }
}

/* === Toast === */
.toast-container { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 99999; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--tokui-text, #333); color: var(--tokui-bg, #fff); padding: 10px 20px; border-radius: 6px; font-size: 0.9em; opacity: 0; transform: translateY(-8px); transition: all 0.3s ease; pointer-events: auto; }
.toast--visible { opacity: 1; transform: translateY(0); }
